package util

import (
	"encoding/json"
	"fmt"
	"math/rand"
	"reflect"
	"time"
)

/**
获取随机字符
*/
func GetRandomString(l int) string {
	str := "0123456789abcdefghijklmnopqrstuvwxyz"
	bytes := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < l; i++ {
		result = append(result, bytes[r.Intn(len(bytes))])
	}
	return string(result)
}

func ToJson(param interface{}) string {
	fmt.Println(&param)

	t := reflect.TypeOf(param)
	v := reflect.ValueOf(param)
	for k := 0; k < t.NumField(); k++ {
		fmt.Printf("%s -- %v \n", t.Field(k).Name, v.Field(k).Interface())
	}

	bytes, _ := json.Marshal(param)

	return string(bytes)
}
